<?php
    require_once 'public/includes/functions.php';
    require_once 'models/container.php';
    require_once 'models/submit.php';
    
    class YKienController extends functions {
        var $container= null;
        var $submitTBL =null;
        var $comment = array();
        
        function __construct(){
            $this->container = new Container_Model(); 
            $this->submitTBL = new Submit_Model();
            $this->getComment();           
        }
        
        public function addAction(){   
            $now=getdate();
        	$date=$now["mday"]."-". $now["mon"]."-". $now["year"];
        	$name=$_POST['ten'];
        	$email=$_POST['email'];
        	$subject=$_POST['subject'];
        	$thongdiep=$_POST['thongdiep'];        	
            if($this->submitTBL->add($name,$email,$subject,$thongdiep,$date)>0){
                unset($_POST);
                $this->submitTBL->ShowMessage('Thông điệp của bạn đã gởi đi thành công');
            }else{
                $this->submitTBL->ShowMessage("Đã xảy ra lỗi, vui lòng thử lại");
            }                 
        }
        
        public function getComment (){
            $sql = "SELECT * FROM Submit ORDER BY id DESC LIMIT 0,4 ";
            $res= $this->submitTBL->ExecuteSQL($sql);
            while($row =  mysql_fetch_assoc($res)){
                $this->comment[] = array(
                                        'id'        =>  $row['id'],
                                        'name'      =>  $row['ten'],
                                        'email'     =>  $row['email'],
                                        'subject'   =>  $row['chude'],
                                        'content'   =>  $row['noidung'],
                                        'postDate'  =>  $row['ngaypost']  
                                    );
            }
            
        }
    }
    
    $ykien = new YKienController();
    if(isset($_POST['submit'])){
        $ykien->addAction();
    }
    
    $ykien->show('ykien');
?>